package com.aaa.stock.controller.api;

import com.aaa.entity.Provider;
import com.aaa.entity.Purchase;
import com.aaa.entity.PurchaseItem;
import com.aaa.stock.service.PurchaseService;
import com.aaa.stock.vo.PurchaseDtoVo;
import com.aaa.stock.vo.PurchaseVo;
import com.aaa.vo.Result;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Objects;


@RestController
@RequestMapping("stock/api/pur")
public class ApiPurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    @PostMapping("pasi/{currentPage}/{pageSize}")
    public Result<IPage<Purchase>> pasi(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody PurchaseVo purchaseVo
    ){
        return  purchaseService.findByAll(currentPage,pageSize,purchaseVo);
    }


    @PostMapping("GetAdd")
    public Result<Boolean> GetAdd(@RequestBody PurchaseDtoVo purchaseVo){
        System.out.println("purchaseVo = " + JSON.toJSONString(purchaseVo));
       Result<Boolean> purchaseDtoVoResult = purchaseService.GetAdd(purchaseVo);
        return purchaseDtoVoResult;
    }

    @PostMapping("Staging")
    public Result<Boolean> Staging(@RequestBody PurchaseDtoVo purchaseVo){
        System.out.println("purchaseVo = " + JSON.toJSONString(purchaseVo));
        Result<Boolean> purchaseDtoVoResult = purchaseService.Staging(purchaseVo);
        return purchaseDtoVoResult;
    }

    @PostMapping("tjsh")
    public Result<Boolean> tjsh(@RequestBody Purchase purchase){
        System.out.println("purchase***********************"+ purchase);
        if (Objects.nonNull(purchase.getPurchaseId())){
            purchase.setUpdateTime(LocalDateTime.now());
        }else {
            purchase.setCreateTime(LocalDateTime.now());
        }
        return purchaseService.tjsh(purchase);
    }

    @PostMapping("zf")
    public Result<Boolean> zf(@RequestBody Purchase purchase){
        System.out.println("purchase***********************"+ purchase);
        if (Objects.nonNull(purchase.getPurchaseId())){
            purchase.setUpdateTime(LocalDateTime.now());
        }else {
            purchase.setCreateTime(LocalDateTime.now());
        }
        return purchaseService.zf(purchase);
    }

    @PostMapping("rk/{purchaseId}")
    public Result<Boolean> rk(@PathVariable String purchaseId){
        return purchaseService.rk(purchaseId);
    }




}


